package com.example.blog.controller;

import com.example.blog.base.Result;
import com.example.blog.entity.Favorites;
import com.example.blog.entity.Follow;
import com.example.blog.entity.vo.favorites.FavoritesDetailInfoVO;
import com.example.blog.entity.vo.follow.FollowDetailInfoVO;
import com.example.blog.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关注模块
 * <p>
 * 关注表 前端控制器
 * </p>
 *
 * @author wlh
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/blog/follow")
public class FollowController {


    @Autowired
    private FollowService followService;

    /**
     * 添加关注
     * @param userId 被关注用户id
     * @return
     */
    @PostMapping("/add/{userId}")
    public Result<Void> add(@PathVariable Long userId) {
        followService.add(userId);
        return Result.success();
    }

    /**
     * 取消关注
     * @param userId 被关注用户id
     * @return
     */
    @DeleteMapping("/del/{userId}")
    public Result<Void> del(@PathVariable Long userId) {
        followService.del(userId);
        return Result.success();
    }

    /**
     * 获取关注列表
     *
     * @return Result<List<Follow>>
     */
    @GetMapping("/new-follow")
    public Result<List<FollowDetailInfoVO>> newFollow() {
        // 调用followService中的newFollow方法获取最新的关注列表，并将其封装在Result对象中返回
        return Result.successData(followService.newFollow());
    }

    /**
     * 将未读更新为已读
     * @return
     */
    @PutMapping("/read")
    public Result<Void> read() {
        followService.read();
        return Result.success();
    }
}
